package com.fenghongzhang.day012;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private MyReceiver2 myReceiver2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //动态注册
         myReceiver2 = new MyReceiver2();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.feng");
        intentFilter.addAction("com.feng1");
        intentFilter.addAction("com.feng3");

        registerReceiver(myReceiver2,intentFilter);
    }

    public void btn1(View view) {

        Intent intent = new Intent();
        intent.setAction("com.feng");
        intent.putExtra("name","小明");
        sendBroadcast(intent);//发送广播

    }

    public void btn2(View view) {
        Intent intent = new Intent();
        intent.setAction("com.feng1");
        Bundle bundle = new Bundle();
        bundle.putString("name1","大明");
        intent.putExtras(bundle);
        sendBroadcast(intent);//发送广播

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myReceiver2);
    }

    public void btn3(View view) {
        Intent intent = new Intent();
        intent.setAction("com.feng3");
        sendOrderedBroadcast(intent,null);
    }
}
